package org.skyeye.modeling.commands;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;
import org.skyeye.modeling.model.MNode;
import org.skyeye.modeling.model.MRoot;


public class CreateNodeCommand extends Command {
	protected MRoot root;

	protected MNode node;

	protected Point location;

	// setters

	public void setRoot(MRoot diagram) {
		this.root = diagram;
	}

	public void setNode(MNode node) {
		this.node = node;
	}

	public void setLocation(Point location) {
		this.location = location;
	}

	public void execute() {
		if (this.location != null) {
			this.node.setLocation(this.location);
		}
		node.setName(root.getDeviceName(node.getBaseName()));
		this.root.addChild(this.node);
		this.node.setRoot(root);
	}

	public String getLabel() {
		return "";
	}

	public void redo() {
		this.execute();
	}

	public void undo() {
		root.removeChild(node);
	}
}